package com.immunology.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.immunology.dao.UserDao;
import com.immunology.domain.User;

@Repository(value="userDao")
@Transactional
public class UserDaoImpl extends GenericDaoImpl<User> implements UserDao{

	@Autowired
	public UserDaoImpl(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	@Override
	@SuppressWarnings("unchecked")
	public User getByLogin(String login) {
		User result = null;
		Criteria criteria = getSessionFactory().getCurrentSession()
				.createCriteria(User.class);
		criteria.add(Restrictions.eq("login", login));
		List<User> users = (List<User>) criteria.list();
		if (!users.isEmpty()) {
			result = users.get(0);
		}
		return result;
	}

}
